package com.flst;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class myAdapter extends BaseAdapter {

	private ArrayList<produit> produits;
	private LayoutInflater myInflater;
	
	public myAdapter (Context context, ArrayList<produit> _produits)
	{
		this.myInflater = LayoutInflater.from(context);
		this.produits = _produits;
	}
	
	@Override
	public int getCount() {
		return this.produits.size();
	}

	@Override
	public Object getItem(int arg0) {
		return this.produits.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public static class ViewHolder {
		TextView text01;
		TextView text02;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		
		if (convertView == null)
		{
			convertView = myInflater.inflate(R.layout.listitem, null);
			holder = new ViewHolder();
			holder.text01 = (TextView) convertView.findViewById(R.id.txtNom);
			holder.text02 = (TextView) convertView.findViewById(R.id.txtDetail);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.text01.setText(produits.get(position).nom);
		holder.text02.setText(produits.get(position).detail);

		return convertView;
		
	}

}
